﻿@model Member
@{
    ViewBag.Title = "登录";
}
<style type="text/css">
    body
    {
         background:rgb(60,135,114) url('/Content/Images/login.jpg') no-repeat;
    }
</style>
@{Html.Telerik().Window().Name("loginBox").Title("登录").HtmlAttributes(new { @class = "LoginWindow" })
    .Buttons(buttons => buttons.Clear())
    .Content(
@<text>
@{using (Ajax.BeginForm<MemberController>(c => c.MemberLogin((Member)null),
  new AjaxOptions { OnBegin = "BeforeSend", OnSuccess = "OnSuccess", OnFailure = "OnError" }))
  {
<table>
    <tr>
        <th>用户名</th>
        <td>@Html.SecureInputFor(model => model.LoginName)</td>
    </tr>
    <tr>
        <th>密码</th>
        <td>@Html.SecurePasswordFor(model => model.Passcode)</td>
    </tr>
</table>
      <input type="submit" id="btnLogin" value="登录" />
  }}
</text>)
    .ClientEvents(
        window => window.OnOpen("OnLoginBoxOpen"))
    .Render();
}
@{Html.Telerik().Window()
    .Name("logging")
    .Title("系统提示")
    .Buttons(buttons => buttons.Clear())
    .Modal(true)
    .Content(
@<text>
正在登录，请稍后...
</text>)
    .Visible(false)
    .ClientEvents(
        window => window.OnOpen("OnLoggingOpen"))
    .Render();
}
@{Html.Telerik().Window()
    .Name("loginError")
    .Title("系统提示")
    .Modal(true)
    .Buttons(buttons => buttons.Close())
    .Content(
@<text>
出现错误，请重试！
</text>)
    .Visible(false)
    .ClientEvents(
        window => window.OnOpen("OnLoginErrorOpen").OnClose("OnLoginErrorClose"))
    .Render();
}
<script type="text/javascript">
    $("#btnLogin").click(function () {
        var txtPasscode = $("#Passcode");
        var password = txtPasscode.val();
        var passcode = password.Base64Encode();
        txtPasscode.val(passcode);  //将密码Base64加密
    });
    function OnLoginBoxOpen() {
        $("#loginBox").data("tWindow").center();
    }
    function OnLoggingOpen() {
        $("#logging").data("tWindow").center();
    }
    function OnLoginErrorOpen() {
        $("#loginError").data("tWindow").center();
    }
    function OnLoginErrorClose() {
        $("#LoginName").val("");
        $("#Passcode").val("");
    }
    function BeforeSend() {
        $("#logging").data("tWindow").open();
    }
    function OnSuccess(data) {
        if (data.success) {
            window.location = "@(Url.Action<HomeController>(c => c.Index()))";
        } else {
            $("#loginError").data("tWindow").open();
            $("#logging").data("tWindow").close();
        }
    }
    function OnError(obj, msg) {
        $("#loginError").data("tWindow").open();
        $("#logging").data("tWindow").close();
    }
</script>